package com.qufadai.reader.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qufadai.reader.entity.TickerEntity;
import com.qufadai.reader.repository.TickerRepository;

@Service
public class TickerService {

	@Autowired
	private TickerRepository tickerRepository;
	
	public void saveTicker(TickerEntity ticker) {
		this.tickerRepository.save(ticker);
	}
	
	public void saveTickerBatch(Iterable<TickerEntity> ite) {
		this.tickerRepository.save(ite);
	}

	public TickerEntity findUserById(Integer id) {
		return this.tickerRepository.findOne(id);
	}

	public void updateTicker(TickerEntity ticker) {
		this.tickerRepository.save(ticker);
	}

	public void deleteUserById(Integer id) {
		this.tickerRepository.delete(id);
	}

	public List<TickerEntity> findBySource(Integer source) {
		return this.tickerRepository.findBySource(source);
	}

	public List<TickerEntity> findBySourceAndUpdated(Integer source,
			Long updated) {
		return this.tickerRepository.findBySourceAndUpdated(source, updated);
	}

	public List<TickerEntity> getMinSell(String coinType) {
		return this.tickerRepository.getMinSell(coinType);
	}

	public List<TickerEntity> findBySourceAndCoinType(Integer source,
			String coinType) {
		return this.tickerRepository.findBySourceAndCoinType(source, coinType);
	}

	public TickerEntity fetchLastBySourceAndCoinType(Integer source,
			String coinType) {

		return this.tickerRepository.fetchLastBySourceAndCoinType(source,
				coinType);
	}
}
